package com.java.zhuiyun.api.sys_dict.controller;

import com.java.zhuiyun.api.sys_dict.entity.SysDict;
import com.java.zhuiyun.api.sys_dict.service.ISysDictService;
import com.java.zhuiyun.common.response.CommonResult;
import com.java.zhuiyun.util.pageUtil.PageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName SysDictController
 * @Description TODO
 * @Author xy
 * @Date 2023/8/15 11:48
 **/
@RestController
@RequestMapping("/Dict")
public class SysDictController {
    @Autowired
    ISysDictService sysDictService;

    /**
    * @Author xy
    * @Description 全查
    * @Date 2023/8/15 15:39
    * @Return  * @param null
    */
    @GetMapping("/SysDictList")
    public CommonResult dictList(SysDict sysDict, PageRequest pageRequest){
        return CommonResult.ok(sysDictService.dictList(sysDict,pageRequest));
    }

    /**
    * @Author xy
    * @Description 添加
    * @Date 2023/8/15 15:39
    * @Return  * @param null
    */
    @PostMapping("/SysDictAdd")
    public CommonResult SysDictAdd(@RequestBody SysDict sysDict){
        int i = sysDictService.SysDictAdd(sysDict);
        if (i>0){
            return CommonResult.ok("恭喜您，添加成功");
        }else {
            return CommonResult.error("很抱歉，添加失败");
        }
    }

    /**
    * @Author xy
    * @Description 修改
    * @Date 2023/8/15 16:26
    * @Return  * @param null
    */
    @PostMapping("/SysDictUpdate")
    public CommonResult SysUserUpdate(@RequestBody SysDict sysDict){
        int i = sysDictService.SysDictUpdate(sysDict);
        if (i>0){
            return CommonResult.ok("恭喜您，修改成功");
        }else {
            return CommonResult.error("很抱歉，修改失败");
        }
    }

    /**
    * @Author xy
    * @Description 逻辑删除
    * @Date 2023/8/15 16:41
    * @Return  * @param null
    */
    @DeleteMapping("/SysDictDelete")
    public CommonResult SysUserDelete(Integer id){
        int i = sysDictService.SysDictDelete(id);
        if (i>0){
            return CommonResult.ok("恭喜您，删除成功");
        }else {
            return CommonResult.error("很抱歉，删除失败");
        }
    }
}
